﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LoA.Shared.Interfaces;
using Microsoft.Xna.Framework;

namespace LoA.CameraEngine.Entities {
	internal sealed class FirstPersonCameraProcessor : CameraProcessorBase {
		public FirstPersonCameraProcessor(Game game) {
			this.objectPosition = Vector3.UnitY * 2;
			this.objectDirection = Vector3.UnitX;

			this.ProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), game.GraphicsDevice.Viewport.AspectRatio, 0.02f, 700.0f);
			this.UpdateViewMatrix( );
		}

		private Vector3 objectPosition;
		public Vector3 ObjectPosition { get { return this.objectPosition; } set { this.objectPosition = value; } }
		private Vector3 objectDirection;
		public Vector3 ObjectDirection { get { return this.objectDirection; } set { this.objectDirection = value; } }
		private Vector3 objectUp;
		public Vector3 ObjectUp { get { return this.objectUp; } set { this.objectUp = value; } }

		private void UpdateViewMatrix( ) {
			this.ViewMatrix = Matrix.CreateLookAt(
				this.ObjectPosition - this.ObjectDirection,
				this.ObjectPosition,
				Vector3.Up
			);
		}

		public override void Update(GameTime gameTime, IInput inputEngine) {
			this.UpdateViewMatrix( );
		}
	}
}
